<script>
  jQuery(document).ready(function(){
    create_scrollable('#week_list', 20, '#week_<?= $this->current_week ?>', 'Week');
    jQuery(".tablesorter").tablesorter({sortList: [[1,1],[2,1],[3,1],[4,1],[5,1],[6,1],[0,0]]}); 
  });
</script>

<form action="index.php" method="post" name="adminForm">

<div id="tabs" style="padding-top:10px;">
  <ul id="week_list">
<?  foreach(array_keys($this->weeks) as $index):?>
    <li id="week_<?= $index ?>">
      <a href="<?= JRoute::_('index.php?option=com_pbny&controller=schedules&task=display&id='.$index) ?>" ><?= ($index+1) ?></a>
    </li>
<?    endforeach ?>

  </ul>
</div>

<?
  $first_team_id    = $this->schedule->first_team_id;
  $second_team_id   = $this->schedule->second_team_id;
  $first_team_name  = $this->schedule->first_team->abbr;
  $second_team_name = $this->schedule->second_team->abbr;
  
  if(empty($first_team_name))
    $first_team_name  = $this->schedule->first_team->name;
  if(empty($second_team_name))
    $second_team_name = $this->schedule->second_team->name;
    
  $potg = null;
  if(isset($this->player_of_the_game))
    $potg = $this->player_of_the_game;
?>

<div class="graph_area">
  <h4>PLAYER OF THE GAME</h4>

  <?
    $PTS = 0; $OFF = 0; $DEF = 0; $ASTS = 0; $STLS = 0; $BLKS = 0;
    $potg_pic     = null;
    $potg_name    = null;
    $potg_team_id = null;
    if(isset($potg) && isset($this->stats[$potg->id])){
      $stat = $this->stats[$potg->id];
      $PTS  = $stat->points;
      $OFF  = $stat->off_rebounds;
      $DEF  = $stat->def_rebounds;
      $ASTS = $stat->assists;
      $STLS = $stat->steals;
      $BLKS = $stat->blocks;
      
      $potg_pic     = $potg->pic;
      $potg_name    = $potg->person->lastname.', '.$potg->person->firstname;
      $potg_team_id = $potg->team_id;
    }    
  ?>
  <div>
    <table style="border:3px solid #444444; background-color:#cccccc; color:#000000">
      <tr>
        <td colspan="2">
          <img src="<?= PBNYHelper::getFlickrImageUrl($potg_pic->flickr_id, 'small') ?>" width="190px" height="190px" />    
        </td>
      </tr>
      <tr>
        <td>
          <b><?= $potg_name ?></b>
        </td>
        <td>
          <? if($potg_team_id == $first_team_id)
               $team_name = $first_team_name;
             else
               $team_name = $second_team_name;
          ?>
          <label>(<?= $team_name?>)</label>
        </td>
      </tr>
      <tr>
        <td>Points</td>
        <td><?= $PTS ?></td>
      </tr>
      <tr>
        <td>Off Rebounds</td>
        <td><?= $OFF ?></td>
      </tr>
      <tr>
        <td>Def Rebounds</td>
        <td><?= $DEF ?></td>
      </tr>
      <tr>
        <td>Assists</td>
        <td><?= $ASTS ?></td>
      </tr>
      <tr>
        <td>Steals</td>
        <td><?= $STLS ?></td>
      </tr>
      <tr>
        <td>Blocks</td>
        <td><?= $BLKS ?></td>
      </tr>
    </table>
  </div>

  <h4>GAME STATS</h4>
<? if(isset($this->graph))
     $graph = $this->graph;
   else
     $graph = '';
?>
  <div class="graph_canvas">
    <img src="<?= JURI::base(true).'/'.$graph ?>" />
  </div>
  
</div>

<div style="min-height:620px;margin: 55px 0px 0px 250px;">
<?  $teams = array($first_team_id => $first_team_name, $second_team_id => $second_team_name);
  foreach($teams as $team_id => $team_name): ?>
    <h3 class="score_highlight">
      <?= $team_name ?>    <?= $this->schedule->final_score[$team_id]?>
    </h3>
    <table style="width:100%;" class="tablesorter">
      <thead>
        <tr>
          <td colspan="2"></td>
          <td colspan="2" class="cell_key">REBS</td>
        </tr>
        <tr>
          <th class="cell_key">NAME</th>
          <th class="cell_key">PTS</th>
          <th class="cell_key">OFF</th>
          <th class="cell_key">DEF</th>
          <th class="cell_key">ASTS</th>
          <th class="cell_key">STLS</th>
          <th class="cell_key">BLKS</th>
        </tr>
      </thead>
      <tbody>
      
<?    if(!empty($this->players)):
        foreach($this->players[$team_id] as $player_id => $name): 
    
        $PTS = 0; $OFF = 0; $DEF = 0; $ASTS = 0; $STLS = 0; $BLKS = 0;
        if(isset($this->stats[$player_id])){
          $stat = $this->stats[$player_id];
          $PTS  = $stat->points;
          $OFF  = $stat->off_rebounds;
          $DEF  = $stat->def_rebounds;
          $ASTS = $stat->assists;
          $STLS = $stat->steals;
          $BLKS = $stat->blocks;
        }    
?>
          <tr>
            <td class="cell_value"><?= $name ?></td>
            <td class="cell_value"><?= $PTS  ?></td>
            <td class="cell_value"><?= $OFF  ?></td>
            <td class="cell_value"><?= $DEF  ?></td>
            <td class="cell_value"><?= $ASTS ?></td>
            <td class="cell_value"><?= $STLS ?></td>
            <td class="cell_value"><?= $BLKS ?></td>
          </tr>
<?      endforeach;
      endif; ?>
      </tbody>
    </table>
<?  endforeach; ?>
</div>
<div class="clear"></div>
</form>
